# coding: utf-8

from elasticsearch import Elasticsearch

es = Elasticsearch(hosts="172.16.212.233:9200")
body = {
    "from": 0,
    "size": 20,
    "query": {
        'bool': {
            'must': [
                {
                    'term': {
                        'title': '我'
                    }
                }
            ]
        },
    },
    "sort": [
        {
            "age": {
                "order": "desc"
            }
        }
    ]
}
res = es.search(index='wangsir', doc_type='user', body=body)
print(res['hits']['total'])
arr = res['hits']['hits']
for item in arr:
    print(item['_source'])
